﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using pos.entity;
using NHibernate.Criterion;
using System.Collections;
namespace pos
{
    public partial class CommoditySelected : Form
    {

        public CommoditySelected()
        {
            InitializeComponent();
        }

        private string id;
        private string rs;
        public string Prepare
        {
            set { id = value; }
        }
        public string Result
        {
            get {
                return rs;
            }

        }
        private void CommoditySelected_Load(object sender, EventArgs e)
        {

            ListView.ColumnHeaderCollection cols=listView1.Columns;
            cols.Add("商品代码",120);
            cols.Add("商品名称",200);
            cols.Add("价格",90);

            if (id == null)
                return;
            if (id.Length != 13)
                return;
            string str=id.Substring(0, 7);
            t_commodity t=new t_commodity();
            DetachedCriteria dc = t.DC.Add(Restrictions.Like("commodityID", str+"%"))
                .Add(Restrictions.Eq("packageFlag",t_commodity.NOPACKAGE))
                .AddOrder(Order.Asc("commodityName"));
            IList list=t.List(dc);
            foreach (Commodity s in list)
            {
               ListViewItem item= listView1.Items.Add(s.commodityID);
               item.SubItems.Add(s.commodityName);
               item.SubItems.Add(s.retailPrice.ToString("0.0"));


            }
            
        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
                return;

            foreach (ListViewItem item in listView1.SelectedItems)
            {
                rs = item.Text;
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }

        }

       
    }
}
